﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LGSVR.Common;
using LGSVR.BLL.Program;

namespace LGSVR_WEB.sys
{
    public partial class UserActList : LGSVR.Common.DataBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (!IsPostBack)
            {
                innit();
                gvDataBind("");
            }

        }

        private void innit()
        {
            lbtnUnable.Attributes.Add("onclick", "return checkStop('ListInfo')");
            lbtnDel.Attributes.Add("onclick", "return checkDel('ListInfo')");
        }

        private void gvDataBind(string p)
        {
            DataTable dt;
            int totalRS;
            int pageIndex;


            if (!string.IsNullOrEmpty(Request.QueryString["pg"]) && Utils.IsNumber(Request.QueryString["pg"]))
            {
                pageIndex = int.Parse(Request.QueryString["pg"]);
            }
            else
            {
                pageIndex = 1;
            }
            dt = GetList("userAct", " id desc ", p, pageIndex, PageSize, out totalRS);
            rptBody.DataSource = dt;
            rptBody.DataBind();
            SplitHtmlCode = Split.GetHtmlCode("userActEdit.aspx", 8, pageIndex, PageSize, totalRS);

        }
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            //同时删除权限表信息，先查询actID
            MessageInfo msgInfo = new MessageInfo();
            if(!string.IsNullOrEmpty(Request["chkId"]))
            {
                string _actID = string.Empty;
                foreach (var id in Request["chkId"].Split(','))
                {
                    _actID = msgInfo.GetstrValue("SELECT actID  FROM userAct WHERE ID = " + id);

                    bool isTrue = Delete("userAct", id);
                    if (isTrue)
                    {
                        //同时删除权限表信息
                        //MessageInfo msgInfo = new MessageInfo();
                        //string _actID = msgInfo.GetstrValue("SELECT actID  FROM userAct WHERE ID = " + Request["chkId"]);
                        isTrue = Delete("ActMenu", "actID", _actID);
                        if (isTrue)
                        {
                            MsgContent = ShowMessage("恭喜您，删除成功！", MessageType.Success, false, true);
                            NoRefresh();
                            return;
                        }
                    }
                }
             }
            //else
            //{
                MsgContent = ShowMessage("对不起,操作失败，请重试。", MessageType.Error, false, true);
            //}
        }

        protected void lbtnUnable_Click(object sender, EventArgs e)
        {
            bool isTrue = UpdateState("userAct", false,Request["chkId"]);
            if (isTrue)
            {
                MsgContent = ShowMessage("恭喜您，停用成功！", MessageType.Success, false, true);
                NoRefresh();
            }
            else
            {
                MsgContent = ShowMessage("对不起,操作失败，请重试。", MessageType.Error, false, true);
            }
        }
        protected void Search(object sender, CommandEventArgs e)
        {
            string strWhere = "";
            if (txtActName.Text.Trim() != "")
            {
                strWhere = " and ActName like '%" + txtActName.Text.Trim() + "%'";
            }
            gvDataBind(strWhere);
        }
    }
}